function [bpimage,fprojs] = backproj(projs,angles,det_space,det_pos,res,filtertype)

% Reconstructs image
%
% [bpimage,fprojs] = backproj(projs,angles,det_space,det_pos,res,filtertype)
%
% Inputs
% angles = angles at which projections are obtained
% ith row of projs = projection at detectors for angles(i)
% res = resolution of the reconstructed image (in the square from (0,0)-(1,1)
% det_space = Spacing of detectors along the projection
% det_pos = detector positions in [-L/2,L/2]
% filtertype = type of filter to be used (conv based or fft based)
%
% Outputs
% bpimage - Reconstructed image
%
% Developed by	Srikrishna Bhashyam and Andy Doran
%               Rice University
% 		March 1, 1999
%		Last Updated - April 17, 1999
%

cx = 0.5;
cy = 0.5;

num_angles = length(angles);

% Filter each projection here
num_dets = length(det_pos);

if (filtertype == 1)
[fprojs,samp_space,samp_pos,f] = convfilter(projs,det_space,det_pos);
else
[fprojs,samp_space,samp_pos,f] = fftfilter(projs,det_space,det_pos);
end

fprintf('Projections filtered\n');

[bpimage] = bproj(fprojs,res,num_angles,samp_space,samp_pos,angles,cx,cy);

